package com.secxiot.common.utils;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.vms.v20200902.VmsClient;
import com.tencentcloudapi.vms.v20200902.models.SendTtsVoiceRequest;
import com.tencentcloudapi.vms.v20200902.models.SendTtsVoiceResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 腾讯语音提醒
 */
public class TXVoiceUtil {
    private static Logger LOG = LoggerFactory.getLogger(TXVoiceUtil.class);

    private static final String SECRET_ID = "AKIDzn7lCQbc6qNedb70slskNmvoTs0Ls32n";
    private static final String SECRET_KEY = "f5SWCbmyufAOMMBk8E5h39JDrJVSEk7Z";
    private static final String VOICE_URL = "vms.tencentcloudapi.com";
    private static final String VOICE_SDK_APPID = "1400471758";

    /**
     * 发送模板消息
     *
     * @param mobile 手机号
     * @param tempId 模板id
     */
    public static void SendTtsVoice(String mobile, String tempId) {
        try {
            Credential cred = new Credential(SECRET_ID, SECRET_KEY);

            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint(VOICE_URL);

            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);

            VmsClient client = new VmsClient(cred, "ap-beijing", clientProfile);
            String[] tempParam = new String[0];
            SendTtsVoiceRequest req = new SendTtsVoiceRequest();
            req.setTemplateParamSet(tempParam);
            req.setVoiceSdkAppid(VOICE_SDK_APPID);
            req.setCalledNumber("+86" + mobile);
            req.setTemplateId(tempId);
            req.setPlayTimes(1L);

            SendTtsVoiceResponse resp = client.SendTtsVoice(req);
            LOG.info(SendTtsVoiceResponse.toJsonString(resp));
        } catch (TencentCloudSDKException e) {
            LOG.error(e.toString());
        }
    }

    public static void main(String[] args) {
        SendTtsVoice("02989184593", "839897");
    }
}
